
find_package(PkgConfig)
pkg_check_modules(PC_XML2  libxml-2.0)

find_path(LIBXML2_INCLUDE_DIRS
    NAMES libxml/xmlstring.h
    HINTS ${PC_XML2_INCLUDEDIR}
    ${PC_XML2_INCLUDE_DIRS}
    PATH_SUFFIXES libxml 
)

find_library(LIBXML2_LIBRARIES
    NAMES xml2
    HINTS ${PC_XML2_LIBDIR}
    ${PC_XML2_LIBRARY_DIRS}
)

if (LIBXML2_INCLUDE_DIRS)
	set(LIBXML2_VERSION "${PC_XML2_VERSION}")
endif ()

if ("${LIBXML2_FIND_VERSION}" VERSION_GREATER "${LIBXML2_VERSION}")
	message(FATAL_ERROR "Required version (" ${LIBXML2_FIND_VERSION} ") is higher than found version (" ${LIBXML2_VERSION} ")")
endif ()

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBXML2  REQUIRED_VARS LIBXML2_INCLUDE_DIRS LIBXML2_LIBRARIES
	VERSION_VAR LIBXML2_VERSION)
set(LIBXML2_INCLUDE_DIR ${LIBXML2_INCLUDE_DIRS})
set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES})
mark_as_advanced(
    LIBXML2_INCLUDE_DIRS
    LIBXML2_INCLUDE_DIR
    LIBXML2_LIBRARIES
    LIBXML2_LIBRARY
)

